<?php /* Smarty version 2.6.20, created on 2013-05-25 07:02:09
         compiled from _core/_include/module/_mvc/control/handledialogobject.tpl */ ?>
function HandleDialogObject(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();

  this._name = (options && options.name) ? options.name : null;
  this._php = (options && options.php) ? options.php : null;
  
  this._createElements();
};

HandleDialogObject.prototype._createElements = function() {
  var tr, td;
  tr = this._gui.objects.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 6;
  td.appendChild(DOMUtils.getLoadingImage());
  this._loadData();
};

HandleDialogObject.prototype._loadData = function() {
  this._objects = null;
  this._retrieveObjects();
};

HandleDialogObject.prototype._verifyData = function() {
  if (this._objects) {
    this._updateElements();
  }
};

HandleDialogObject.prototype._retrieveObjects = function() {
  var _self = this;
  /*new RequestUtils()._read(this._name, null, null, null, null, null, null, function(result, params) { _self._objects = result.data;
                                                                                                      _self._verifyData.call(_self);
                                                                                                    }, {php : this._php});*/
  new RequestUtils()._mysql(this._name, null, function(result, params) { _self._objects = result.data;
                                                                           _self._verifyData.call(_self);
                                                                         }, {php: this._php});                                                                                                    
};

HandleDialogObject.prototype._updateElements = function() {
  var table, tr, td, radio, input, _self = this;
  DOMUtils.removeTableRows(this._gui.objects, 1);
  
  this._gui.object.onchange = function() { _self._item.name = this.value; };
  
  MiscUtils.sort(this._objects, ['name']);
  
  for (var i = 0, il = this._objects.length; i < il; i++) {
    var obj = this._objects[i];
    if (i % 3 == 0) {
      tr = this._gui.objects.insertRow(-1);
    }
    td = tr.insertCell(-1);
    td.style.height = '20px';
    td.style.paddingLeft = '10px';
    td.style.textAlign = 'left';
    td.style.width = '210px';
    td.appendChild(document.createTextNode(obj.name));
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.width = '30px';
    var remove = document.createElement('img');
    remove.src = 'images/common/delete.png';
    remove.style.cursor = 'pointer';
    remove._obj = obj;
    remove.onclick = function() { var pos = DOMUtils.findPos(this);
                                  new RequestUtils()._mwrite(_self._name, [], [this._obj], function() { _self._retrieveObjects(); }, { pos: pos });
                                };
    td.appendChild(remove);
  }
};